// Force.cpp: implementation of the CForce class.
// Copyright (c) 2009, Dan Heeks
// This program is released under the BSD license. See the file COPYING for details.

#include "stdafx.h"
#include "Force.h"
#include "interface/Tool.h"
#include "interface/MarkedObject.h"
#include "tinyxml/tinyxml.h"

CForce::CForce(double x, double y, double z, double vx, double vy, double vz)
{
	m_p[0] = x;
	m_p[1] = y;
	m_p[2] = z;
	m_v[0] = vx;
	m_v[1] = vy;
	m_v[2] = vz;
}

CForce::CForce(const CForce &m){
	operator=(m);
}

CForce::~CForce()
{
}

const CForce& CForce::operator=(const CForce &m){
	memcpy(m_p, m.m_p, 3*sizeof(double));
	memcpy(m_v, m.m_v, 3*sizeof(double));

	return *this;
}

void CForce::glCommands(bool select, bool marked, bool no_color){
}

void CForce::GetBox(CBox &box)
{
}

HeeksObj *CForce::MakeACopy(void)const
{
	return new CForce(*this);
}

bool CForce::ModifyByMatrix(const double *mat){

	return false;
}

void CForce::GetTools(std::list<Tool*>* t_list, const wxPoint* p)
{
	//force_for_tools = this;
	//t_list->push_back(&some_tool);

	HeeksObj::GetTools(t_list, p);
}

bool CForce::Stretch(const double *p, const double* shift, void* data)
{
	return false;
}

void CForce::WriteXML(TiXmlNode *root)
{
	TiXmlElement * element = new TiXmlElement( "force" );
	root->LinkEndChild( element ); 

	element->SetDoubleAttribute("x", m_p[0]);
	element->SetDoubleAttribute("y", m_p[1]);
	element->SetDoubleAttribute("z", m_p[2]);

	element->SetDoubleAttribute("vx", m_v[0]);
	element->SetDoubleAttribute("vy", m_v[1]);
	element->SetDoubleAttribute("vz", m_v[2]);
}

// static
HeeksObj* CForce::ReadFromXMLElement(TiXmlElement* element)
{
	CForce* new_object = new CForce(0, 0, 0, 0, 0, 0);

	element->Attribute("x", &new_object->m_p[0]);
	element->Attribute("y", &new_object->m_p[1]);
	element->Attribute("z", &new_object->m_p[2]);

	element->Attribute("vx", &new_object->m_v[0]);
	element->Attribute("vy", &new_object->m_v[1]);
	element->Attribute("vz", &new_object->m_v[2]);

	return new_object;
}
